<?php
defined('_JEXEC') or die('Restricted access');

class modListBookHelper
{
    /**
     * lay danh sach ma linh vuc trong csdl
     */
    function getList()
	{
		$db = JFactory::getDBO();
 
		$query = ("SELECT * FROM #__linhvuc " );
		$db->setQuery($query);
		$listbook = $db->loadObjectList('ma_linhvuc');
        $index = 0;
        $param = array();
        foreach($listbook as $book)
        {
            $param[$index] = $listbook[$index + 1]->ma_linhvuc;
            $index++;
        }
		return $param;
	}
    
    /**
     * lay danh sach tung cuon sach theo tung linh vuc
     */
	function getListBook($paramoption)
	{
		$db = JFactory::getDBO();
       
		$query = "SELECT DISTINCT c.* FROM #__linhvuc as a,#__linhvuc_con as b, #__cuonsach as c  where a.ma_linhvuc=b.linhvuc_type and b.ma_linhvuc_con=c.linhvuc_cuonsach and a.ma_linhvuc =" . $paramoption ." ORDER BY RAND() limit 21";
		$db->setQuery($query);
		$listbook = $db->loadRowList();
		return $listbook;
	}
    
    /**
     * lay ten linh vuc theo tung linh vuc
     */
    function getSecTion($paramoption)
	{
		$db = JFactory::getDBO();
 
		$query = ("SELECT * FROM #__linhvuc where ma_linhvuc =" . $paramoption );
		$db->setQuery($query);
		$listbook = $db->loadObject();
        $param = $listbook->ten_linhvuc;
		return $param;
	}
    
    /**
     * lay ten linh vuc con theo tung linh vuc con
     */
    function getNameChildField($ma_linhvuc_con)
	{
		$db = JFactory::getDBO();
 
		$query = ("SELECT * FROM #__linhvuc_con where ma_linhvuc_con =" . $ma_linhvuc_con );
		$db->setQuery($query);
		$listbook = $db->loadObject();
        $param = $listbook->ten_linhvuc_con;
		return $param;
	}
    
    /**
     * lay danh sach ma linh vuc con theo tung linh vuc
     */
    function getListField($maLinhvuc)
	{
		$db = JFactory::getDBO();
 
		$query = ("SELECT * FROM #__linhvuc_con where linhvuc_type=" . $maLinhvuc );
		$db->setQuery($query);
		$listbook = $db->loadObjectList('ma_linhvuc_con');
        $index = 0;
        $param = array();
        foreach($listbook as $book)
        {
            $param[$index] = $listbook[$index + 1]->ma_linhvuc_con;
            $index++;
        }
		return $param;
	}
    
    /**
     * lay cac cuon sach theo tung linh vuc con
     */
    function getListBookInField($maLinhVucCon)
	{
		$db = JFactory::getDBO();
       
		$query = "SELECT DISTINCT c.* FROM #__linhvuc_con as b, #__cuonsach as c  where b.ma_linhvuc_con=c.linhvuc_cuonsach and b.ma_linhvuc_con=" . $maLinhVucCon . " ORDER BY RAND() limit 21";
		$db->setQuery($query);
		$listbook = $db->loadRowList();
		return $listbook;
	}
    
    /**
     * lay cuon sach theo ma cuon sach
     */
    function getBookInMa($ma_cuonsach)
	{
		$db = JFactory::getDBO();
 
		$query = ("SELECT * FROM #__cuonsach where ma_cuonsach =" . $ma_cuonsach );
		$db->setQuery($query);
		$listbook = $db->loadRow();
		return $listbook;
	}
    
}
?>
